package com.cyufeng.blog.repository;

import com.cyufeng.blog.entity.Article;
import com.cyufeng.blog.entity.Mood;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;
/**
 * 心情
 * @author Cyufeng
 * Data:2018.12.30
 */
@Repository
public interface MoodRepository extends JpaRepository<Mood,Integer> {
//    查询所有的心情
    @Query(value = "select * from mood t where t.DR ='0' ORDER BY MADE_TIME DESC",nativeQuery = true)
    List<Mood> getAllMood();

    //    查询所有的心情
    @Query(value = "select * from mood t where t.DR ='0' ORDER BY MADE_TIME DESC", countQuery = "select count(*) from mood t where t.DR ='0' ORDER BY MADE_TIME DESC", nativeQuery = true)
    Page<Mood> getAllMood(int id, Pageable pageable);

    /**
     * 删除心情
     *
     * @return
     */
    @Modifying
    @Query(value = "update mood t set t.DR = 1 where t.id =?", nativeQuery = true)
    void deleteMood(int id);


}
